Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make client port configurable through environment variable #352

Merged
merged 1 commit into from Sep 18, 2018

Conversation

0x-r4bbit
Copy link
Contributor

No description provided.

package.json Outdated
@@ -75,7 +75,7 @@
},
"scripts": {
"ui-assets": "copy-aragon-ui-assets -n aragon-ui ./build",
"start": "npm run ui-assets && parcel serve src/index.html --port 3000 --out-dir ./build --no-cache",
"start": "npm run ui-assets && parcel serve src/index.html --port $ARAGON_CLIENT_PORT || 3000 --out-dir ./build --no-cache",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @izqui pointed out offline, this expression doesn't actually work in Bash. Only test when $ARAGON_CLIENT_PORT was set.

Will update.

@0x-r4bbit
Copy link
Contributor Author

Bash makes it really hard to read and repetitive as well.. Another way to go about this is using something like if-env. Let me know if you want me to give this a spin.

@bpierre
Copy link
Contributor

bpierre commented Sep 11, 2018

Maybe we could move the start script to scripts/start.sh? Or even to a node script, for Windows compatibility.

@0x-r4bbit
Copy link
Contributor Author

Oh yea, totally. I like that

@sohkai
Copy link
Contributor

sohkai commented Sep 11, 2018

It looks like cross-var could be viable too, but it's not widely used and a node script might not be much more effort (and would pave the way for the scripts/start_local.sh to be converted too).

For future reference though, parameter substitution might've been nicer in the script (could just use ${ARAGON_CLIENT_PORT:-3000}).

scripts/start.sh Outdated
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

if [[ ${ARAGON_CLIENT_PORT} ]];
Copy link
Contributor

@sohkai sohkai Sep 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should add a REACT_APP prefix, given that all the other env vars use it.

Alternatively, we could change all the other env vars to not use that prefix since we don't need it anymore after moving to parcel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should add a REACT_APP prefix, given that all the other env vars use it.

I don't have super strong feelings about it, just that I think that bit of information, whether it's a react app or not, is not really necessary in that env variable.

But I'm happy to change it regardless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on a second thought, I have to say I probably should've stayed consistent with how env variables have been named in the past. I didn't know REACT_APP_* vars were related to the wrapper client.

@0x-r4bbit
Copy link
Contributor Author

For future reference though, parameter substitution might've been nicer in the script (could just use ${ARAGON_CLIENT_PORT:-3000}).

Ha, that's awesome! Thanks for pointing this out.

I guess I'll convert this script to node then and update the PR

@0x-r4bbit
Copy link
Contributor Author

Alright, this is done. PTAL and let me know if you want to change the env variable.

Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ Looking good!

scripts/start.js Outdated
@@ -0,0 +1,7 @@
const execute = require('child_process').execSync
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add the #!/usr/bin/env node here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is already a JS file and executed with node so I don't think this is needed. Unless, of course, you say you want this executable as a plain text file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to include that as an option, in case someone ever does want to.

I'd find it weird to have to use node scripts/start.js rather than just scripts/start.js directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sure. I thought this was rather a thing to do when you do indeed have a plain text file (without .js extension). I'll update it :)

scripts/start.js Outdated
@@ -0,0 +1,7 @@
const execute = require('child_process').execSync

const clientPort = process.env.ARAGON_CLIENT_PORT || 3000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now it's easiest to stay consistent and use the REACT_APP prefix, and then we can wholesale remove it from both this repo and aragon-cli in one go after.

@0x-r4bbit
Copy link
Contributor Author

Thanks for the review @sohkai ! I'll update this.

This commit also moves the npm start script into scripts/start for
better readability and maintainability.
@0x-r4bbit
Copy link
Contributor Author

@sohkai updated it once more. Notice that I've also dropped the .js extension and went with a plain file instead. This felt more natural to me for this use case and lets you run ./scripts/start.

Let me know if you want to keep the .js extension.

Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@izqui
Copy link
Contributor

izqui commented Sep 18, 2018

Good to merge @bpierre?

@bpierre
Copy link
Contributor

bpierre commented Sep 18, 2018

@izqui I wonder how the execute() would work on WIN environments, but we can see that later. LGTM 👍

@izqui izqui merged commit 66f86ff into aragon:master Sep 18, 2018
@0x-r4bbit 0x-r4bbit deleted the feat/client-port-env-var branch September 18, 2018 16:32
@0x-r4bbit
Copy link
Contributor Author

Happy to see this landed! @bpierre I haven't tested this on Windows, but I also couldn't find any active issues on execSync with Windows. Anything in particular you're aware of?

@bpierre
Copy link
Contributor

bpierre commented Sep 18, 2018

@PascalPrecht Cool! No it’s just that I’m not very familiar with the Windows CLI: I know Unix path separators are accepted, but I was wondering if && and stdio: 'inherit' would work the same way.

@0x-r4bbit
Copy link
Contributor Author

Got it. I guess this needs to be tested then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants